import { defHttp } from '@/utils/http';
import { root, org } from '@/api/apiRoot';
import type { EditPersonalCardDetailsData, EditUnitCardDetailsData, PersonalCardDetailsResult, ProductListResult, UnitCardDetailsResult } from './types';
import type { IQuery, IResData } from '../indexTypes';

export const Api = {
  businessCardCompany: root + 'businessCard/company',
  businessCardPersonal: root + 'businessCard/personal',
  orgBusinessCardCompany: org + 'businessCard/company',
  orgBusinessCardPersonal: org + 'businessCard/personal',

  orgCardProductCategoryList: org + 'businessCard/productCategory/list',
  orgCardPersonalProductList: org + 'businessCard/product/pageCard',
  cardPersonalSelectedProductIds: root + 'businessCard/product/getCardProductIds',
  businessCardProductList: root + 'businessCard/product/pageList'
};

/**
 * @description 获取主库单位名片
 * @date 21/02/2023
 * @export
 * @param {number} cocId
 */
export function orgBusinessCardCompany(cocId: number) {
  return defHttp.get<UnitCardDetailsResult>({
    url: Api.orgBusinessCardCompany + `/${cocId}`,
  });
}

/**
 * @description 编辑单位名片
 * @date 03/09/2022
 * @export
 * @param {EditUnitCardDetailsData} data
 */
export function editUnitCardDetails(data: EditUnitCardDetailsData) {
  return defHttp.post({
    url: Api.businessCardCompany,
    data,
  });
}

/**
 * @description 获取主库个人名片
 * @date 21/02/2023
 * @export
 * @param {number} userId
 */
export function orgBusinessCardPersonal(userId: number, isOneSelfShare: boolean = false) {
  return defHttp.get<PersonalCardDetailsResult>({
    url: Api.orgBusinessCardPersonal + `/${userId}?isOneSelfShare=${isOneSelfShare}`,
  });
}

/**
 * @description 编辑个人名片
 * @date 03/09/2022
 * @export
 * @param {EditPersonalCardDetailsData} data
 */
export function editPersonalCardDetails(data: EditPersonalCardDetailsData) {
  return defHttp.post({
    url: Api.businessCardPersonal,
    data
  });
}

/**
 * @description 获取名片中商品分类
 * @date 17/11/2023
 * @export
 * @param {number} categoryId
 */
export function getOrgCardProductCategoryList(categoryId: number) {
  return defHttp.get<{ id: number, name: string }[]>({
    url: Api.orgCardProductCategoryList + `/${categoryId}`
  });
}

/**
 * @description 获取个人名片中商品列表
 * @date 17/11/2023
 * @export
 * @param {(IQuery & { productCategoryId: number })} data
 */
export function getOrgCardPersonalProductList(data: IQuery & { productCategoryId: number }) {
  return defHttp.post<IResData<ProductListResult>>({
    url: Api.orgCardPersonalProductList,
    data
  });
}

/**
 * @description 获取名片已选择商品IDS
 * @date 17/11/2023
 * @export
 * @param {number} memberLeadingId
 */
export function getCardPersonalSelectedProductIds(memberLeadingId: number) {
  return defHttp.get<number[]>({
    url: Api.cardPersonalSelectedProductIds + `/${memberLeadingId}`
  });
}

/**
 * @description 获取商品列表
 * @date 17/11/2023
 * @export
 * @param {{ productLibIds: number[], memberLeadingId: number }} data
 */
export function getBusinessCardProductList(data: { productLibIds: number[], memberLeadingId: number }) {
  return defHttp.post<IResData<ProductListResult>>({
    url: Api.businessCardProductList,
    data
  });
}